/**
 * Created by Jie on 2017/2/8.
 */
var Model = require('../../model/business/devices_garrison_config');

var index = {page:'business/devices_garrison_config',title:''};
var form = {page:'business/_form/_devices_garrison_config_form',title:'驻防参数管理'};

exports.index = function (req,res) {
    res.render(index.page, {title: index.title});
};

exports.form = function (req,res) {
    var model = new Model();
    model.one(req.params.id,function (err,result) {
        if(result.error == 1){
            res.render(form.page, {title: form.title});
        }else{
            res.render(form.page, {title: form.title,obj:result.data});
        }
    })
};

exports.one = function (req,res) {
    var model = new Model();
    model.one(req.params.id,function (err,result) {
        res.json(result);
    })
}

exports.insert = function (req,res) {
    var model = new Model();
    var json = req.body;
    model.insert(json,function (err,result) {
        res.json(result);
    });
}

exports.edit = function (req,res) {
    var model = new Model();
    var json = req.body;
    var id = req.params.id;
    json.id = id;
    model.edit(json,function (err,result) {
        res.json(result);
    });
}

exports.del = function (req,res) {
    var model = new Model();
    req.body.id = req.params.id;
    model.del(req.body,function (err,result) {
        res.json(result);
    });
}

exports.list = function (req,res) {
    var model = new Model();
    var where = req.body;
    model.list(where,function (err,result) {
        if(err){
            res.json(result);
        }
        res.json(result);
    });
}

exports.all = function (req,res) {
    var model = new Model();
    var cond = {where:'',order:''};
    model.all(cond,function (err,result) {
        res.json(result);
    });
}